<?php


namespace App\Exports;

use App\Models\RecordPay;
use Carbon\Carbon;
use Maatwebsite\Excel\Concerns\FromView;
use Illuminate\Contracts\View\View;
/**
 * Created By FreeAbrams
 * Date: 2020/12/2
 */
class DailyExport implements FromView
{
	protected $timeBetween;
	protected $pay_type = [1 => '现金', 2 => '支付', 3 => '微信', 4 => '银行',  5 => '挂单', 6 => '余额', 7 => '小程支付'];
	
	public function __construct($timeBetween)
	{
		$this->timeBetween = $timeBetween;
	}
	
	public function view():View
	{
		$temp = $this->data($this->timeBetween);
		//dd($temp);
		return view('admin.export.daily-export-table', [
			'data' => $temp,
			'pay_type' => $this->pay_type
		]);
	}
	
	protected function data($timeBetween)
	{
		$recodePays = RecordPay::whereBetween('created_at', $timeBetween)
			->get(['id', 'pay_type', 'price', 'created_at']);
		// 支付类型分组
		$recodePays = $recodePays->groupBy('pay_type');
		
		return $recodePays;
	}
}